<template lang="pug">
.detail
  .detail-header
    .iconfont.icon-back(@click="$router.back()")
    .detail-header-title 订单详情
  .detail-content
    .detail-section
      .section-title
        span 基本信息
      .section-body.detail-spec
        .spec-col
          .spec-row
            .spec-row-label 订单号
            .spec-row-value {{detail.orderInfo.orderNo}}
          .spec-row
            .spec-row-label 供应商用户
            .spec-row-value {{detail.orderInfo.supplier}}
          .spec-row
            .spec-row-label 收货人
            .spec-row-value {{detail.orderLogistic.receiverName}}
          .spec-row
            .spec-row-label 收货地址
            .spec-row-value {{detail.orderLogistic.address}}
        .spec-col
          .spec-row
            .spec-row-label 下单用户
            .spec-row-value {{detail.orderInfo.designer}}
          .spec-row
            .spec-row-label 下单时间
            .spec-row-value {{detail.orderInfo.orderTime}}
          .spec-row
            .spec-row-label 收货联系方式
            .spec-row-value {{detail.orderLogistic.mobile}}
  .detail-content
    .detail-section
      .section-title
        span 订单详情
        .section-title-line
      .section-body
        el-table(
          :data="detail.orderList.detail"
          :header-cell-style="{ fontSize: '14px', color: '#64698F', background: '#F8F7FC' }"
          border
          style="width: 100%"
          empty-text="未找到符合条件的内容"
          :span-method="objectSpanMethod"
        )
          el-table-column(label="图片" prop="supplierName")
            template(slot-scope="scope")
              .table-item-img(:style="scope.row.img | filterUrl")
          el-table-column( label="材料名称" prop="materialName")
          el-table-column( label="规格属性" prop="spec")
            template(slot-scope="scope")
              .table-spec
                .spec-item(v-for="item in scope.row.spec") {{item.specName}}：{{item.specValue}}
          el-table-column( label="数量" prop="num")
          el-table-column( label="订单备注" prop="supplierName")
            template(slot-scope="scope")
              .table-item-spec
                .spec-item {{detail.orderList.remark}}
  .detail-content
    .detail-section
      .section-title
        span 自定义属性
        .section-title-line
      .section-body.custom-attr
        .attr-item
          .attr-item-label 物流公司：
          .attr-item-value {{detail.orderLogistic.shippingCompany}}
        .attr-item
          .attr-item-label 物流单号：
          .attr-item-value {{detail.orderLogistic.trackNumber}}
        .attr-item.start
          .attr-item-label 物流照片：
          .attr-item-value
            .attr-item-img(:style="detail.orderLogistic.trackPhoto | filterUrl")
</template>

<script>
import { getOrderDetail } from 'api'
export default {
  name: 'orderDetail',
  data () {
    return {
      detail: {
        orderInfo: {},
        orderList: {
          detail: []
        },
        orderLogistic: {}
      },
    }
  },
  methods: {
    objectSpanMethod({ row, column, rowIndex, columnIndex }) { // 合并单元格
      if (columnIndex === 4) {
        if (rowIndex % 100 === 0) {
          return {
            rowspan: 100,
            colspan: 1
          }
        } else {
          return {
            rowspan: 0,
            colspan: 0
          }
        }
      }
    },
    async getDetail () {
      try {
        const { ResultSet } = await this.$axios.post(getOrderDetail, { orderId: this.$route.params.id })
        this.detail = ResultSet.userData
      } catch (err) {
        console.log(err)
        this.$message.error(err.message || err.ResultSet.errors)
      }
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      vm.getDetail()
    })
  }
} 
</script>

<style lang="scss" scoped>
.detail {
  width: 100%;
  min-height: 100%;
  background: #fff;
  border: 1px solid #F3F3F4;
  box-sizing: border-box;
  box-shadow: 0px 4px 0px #F3F3F4;
  border-radius: 10px;
}
.detail-header {
  display: flex;
  align-items: center;
  padding: 23px 40px;
  border-bottom: 1px solid #EDEDED;
  .iconfont {
    font-size: 24px;
    color: #B2B4C7;
    margin-right: 12px;
    cursor: pointer;
  }
  .detail-header-title {
    font-weight: bold;
    font-size: 18px;
    line-height: 26px;
    color: #3E4373;
  }
}
.detail-content {
  padding: 40px;
}
.detail-section {
  margin-bottom: 40px;
}
.section-title {
  position: relative;
  font-weight: bold;
  font-size: 18px;
  line-height: 26px;
  color: #B2B4C7;
  margin-bottom: 16px;
  &:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 10px;
    background: #B2B4C7;
    border-radius: 8px;
    z-index: 2;
  }
  span {
    position: relative;
    z-index: 1;
    display: inline-block;
    background: #fff;
    padding: 0 8px 0 12px;
  }
  .section-title-line {
    width: 100%;
    height: 1px;
    background: #EDEDED;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }
}
.detail-spec {
  display: flex;
  width: 100%;
  background: #F6F6F9;
  border-radius: 6px;
  padding: 24px;
}
.spec-col {
  width: 33.33%;
  &:last-child {
    margin-bottom: 0;
  }
  .spec-row {
    margin-bottom: 24px;
    .spec-row-label {
      font-size: 14px;
      line-height: 22px;
      color: #8B8EAB;
    }
    .spec-row-value {
      font-size: 16px;
      line-height: 24px;
      color: #3E4373;
      margin-top: 4px;
      display: flex;
      align-items: center;
    }
    .spec-row-tag {
      padding: 1px 10px;
      font-size: 14px;
      line-height: 22px;
      color: #3E4373;
      background: rgba(134, 118, 255, 0.1);
      border-radius: 6px;
      margin-right: 8px;
    }
  }
}
.table-item-img {
  width: 160px;
  height: 120px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}
.spec-item {
  font-size: 14px;
  line-height: 22px;
}
.custom-attr {
  background: #F6F6F9;
  border-radius: 6px;
  padding: 24px;
  .attr-item {
    display: flex;
    align-items: center;
    &.start {
      align-items: flex-start;
      .attr-item-label {
        line-height: 35px;
      }
    }
    .attr-item-label {
      font-size: 14px;
      line-height: 22px;
      color: #8B8EAB;
    }
    .attr-item-value {
      font-size: 14px;
      line-height: 22px;
      color: #3E4373;
    }
  }
}
.attr-item-img {
  width: 168px;
  height: 80px;
  border-radius: 6px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
</style>
